/*===============================================
New Camera Implementation using Quaternion
Rob Cavanaugh
Created : 11/05/2008
Last Modified : 2/04/2009
=================================================*/
#pragma once
#include <d3d9.h>
#include <d3dx9tex.h>
#include <d3dx9.h>
#include<math.h>                         
#include"Vector3D.h" 
#include "GlobalDefines.h"

const D3DXVECTOR3 defCamOffset(0.0f , 0.0f , 0.0f); // Camera Offset for 3rd person    

#define FORWARD         1.0               // Forward speed.
#define BACKWARD        -1.0              // Backward speed.
#define UP              0.03              // Up speed.
#define DOWN            -0.03             // Down speed.
#define LEFT            -0.03             // Left speed.
#define RIGHT           0.03              // Right speed.
#define STRAFE_LEFT     1.0               // Left straft speed.
#define STRAFE_RIGHT    -1.0              // Right straft speed.

#define GET_COS(a, b)   a = (float)cos(b) // Get the cos angle of b and store it in a.
#define GET_SINE(a, b)  a = (float)sin(b) // Get the sine angle of b and store it in a.

class Camera
{
private:

	float distance;
	float height;
	D3DXVECTOR3 mPos;                                  // Camera position.
    D3DXVECTOR3 mView;                                 // Look at position.
    D3DXVECTOR3 mUp;                                   // Up direction.
    D3DXVECTOR3 mStrafe;                               // Strafe direction.
	float currentRotationAngle;                        // Keeps us from going too far up or down.

public:

    Camera();                                      // Constructor.

	void SetCamera(float x, float y, float z,       // Set the camera's position.
			       float xv, float yv, float zv,
			       float xu, float yu, float zu);

	void createCamera(float nearClip, float farClip);
	void pointCamera();
	void addDistance(float addnum){ addnum=addnum*-1; distance+=addnum;}
	void rotUp(float);
	void rotDown(float);

	void GetDirection(D3DXVECTOR3 &Direction);         // Get the view direction.
	void MoveCamera(float speed);                   // Move the camera forwards and backwards.
		
	void UpdateCamera();
	void StrafeCam(float speed);
	void CalculateStrafe();                            // Calculate the direction of the straft.
	void RotateCamera(float AngleDir, D3DXVECTOR3 Speed); // Rotate the camera around a point.
	void RotateByMouse(int mousePosX, int mousePosY, int midX, int midY);
	void CrossProduct(D3DXVECTOR3 m_direction, D3DXVECTOR3 m_tDir );
	float getDistance(){return distance;}
};
